package com.dreamwhale.machinery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.entity.Lease;
import com.dreamwhale.machinery.dao.LeaseMapper;
import com.dreamwhale.machinery.service.LeaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 去租赁 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-06-06
 */
@Service
public class LeaseServiceImpl extends ServiceImpl<LeaseMapper, Lease> implements LeaseService {

    @Resource
    private LeaseMapper leaseMapper;

    @Override
    public int insertLeases(Lease lease) {
        lease.setCreateTime(LocalDateTime.now());
        return leaseMapper.insert(lease);
    }

    @Override
    public List<Lease> selectLeaseByUserId(Integer userId) {
        QueryWrapper<Lease> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId).eq("del_flag", 2);
        return leaseMapper.selectList(queryWrapper);
    }

    @Override
    public List<Lease> selectLeases(Integer infoId) {
        QueryWrapper<Lease> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_flag", 2).eq("id", infoId);
        return leaseMapper.selectList(queryWrapper);
    }

    @Override
    public Lease selectLeaseByLeadeIds(Integer infoId) {
        return leaseMapper.selectLeaseByLeadeIds(infoId);
    }
}
